<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="耳标号" prop="earNumber">
        <el-input
          v-model="queryParams.earNumber"
          placeholder="请输入耳标号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="买方名称" prop="sellerName">
        <el-input
          v-model="queryParams.sellerName"
          placeholder="请输入买方名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="卖方名称" prop="sellerPhone">
        <el-input
          v-model="queryParams.sellerPhone"
          placeholder="请输入卖方名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="承运人电话" prop="carrierPhone">
        <el-input
          v-model="queryParams.carrierPhone"
          placeholder="请输入承运人电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

<!--    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dgw:fold:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dgw:fold:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dgw:fold:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['dgw:fold:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table v-loading="loading" :data="foldList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="交易时间" align="center" prop="dealTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dealTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="买方" align="center" prop="buyer" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="地址(某镇某村)" align="center" prop="address" width="120"/>
      <el-table-column label="数量" align="center" prop="csum" />
      <el-table-column label="耳标号" align="center" prop="earNumber" />
      <el-table-column label="毛重" align="center" prop="roughWeight" />
      <el-table-column label="单价" align="center" prop="unitPrice" />
      <el-table-column label="金额" align="center" prop="money" />
      <el-table-column label="买方名称" align="center" prop="sellerName" />
      <el-table-column label="卖方名称" align="center" prop="sellerPhone" />
      <el-table-column label="卖方地址" align="center" prop="sellerAddress" />
      <el-table-column label="检验检疫证号" align="center" prop="certificateNumber" width="120" />
      <el-table-column label="承运人" align="center" prop="carrier" />
      <el-table-column label="承运人电话" align="center" prop="carrierPhone" />
      <el-table-column label="车牌号" align="center" prop="licensePlateNumber" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dgw:fold:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dgw:fold:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改交易_调入对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="交易时间" prop="dealTime">
          <el-date-picker clearable size="small"
                          v-model="form.dealTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择交易时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="买方" prop="buyer">
          <el-input v-model="form.buyer" placeholder="请输入买方" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="地址(某镇某村)" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址(某镇某村)" />
        </el-form-item>
        <el-form-item label="数量" prop="csum">
          <el-input v-model="form.csum" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="耳标号" prop="earNumber">
          <el-input v-model="form.earNumber" placeholder="请输入耳标号" />
        </el-form-item>
        <el-form-item label="毛重" prop="roughWeight">
          <el-input v-model="form.roughWeight" placeholder="请输入毛重" />
        </el-form-item>
        <el-form-item label="单价" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="金额" prop="money">
          <el-input v-model="form.money" placeholder="请输入金额" />
        </el-form-item>
        <el-form-item label="买方名称" prop="sellerName">
          <el-input v-model="form.sellerName" placeholder="请输入买方名称" />
        </el-form-item>
        <el-form-item label="卖方名称" prop="sellerPhone">
          <el-input v-model="form.sellerPhone" placeholder="请输入卖方名称" />
        </el-form-item>
        <el-form-item label="卖方地址" prop="sellerAddress">
          <el-input v-model="form.sellerAddress" placeholder="请输入卖方地址" />
        </el-form-item>
        <el-form-item label="检验检疫证号" prop="certificateNumber">
          <el-input v-model="form.certificateNumber" placeholder="请输入检验检疫证号" />
        </el-form-item>
        <el-form-item label="承运人" prop="carrier">
          <el-input v-model="form.carrier" placeholder="请输入承运人" />
        </el-form-item>
        <el-form-item label="承运人电话" prop="carrierPhone">
          <el-input v-model="form.carrierPhone" placeholder="请输入承运人电话" />
        </el-form-item>
        <el-form-item label="车牌号" prop="licensePlateNumber">
          <el-input v-model="form.licensePlateNumber" placeholder="请输入车牌号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFold, getFold, delFold, addFold, updateFold, exportFold } from "@/api/dgw/fold";

export default {
  name: "Qiugou",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 交易_调入表格数据
      foldList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        earNumber: null,
        sellerName: null,
        sellerPhone: null,
        carrierPhone: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询交易_调入列表 */
    getList() {
      this.loading = true;
      listFold(this.queryParams).then(response => {
        this.foldList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dealTime: null,
        buyer: null,
        phone: null,
        address: null,
        csum: null,
        earNumber: null,
        roughWeight: null,
        unitPrice: null,
        money: null,
        sellerName: null,
        sellerPhone: null,
        sellerAddress: null,
        certificateNumber: null,
        carrier: null,
        carrierPhone: null,
        licensePlateNumber: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加交易_调入";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFold(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改交易_调入";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFold(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFold(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除交易_调入编号为"' + ids + '"的数据项？').then(function() {
        return delFold(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有交易_调入数据项？').then(() => {
        this.exportLoading = true;
        return exportFold(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
